package dao.impl;

import dao.BaseDao;
import dao.RainQualityDao;
import entity.Rainquality;

import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @Author: DELL
 * @Since: 2024/6/24 09:45
 * @Description:
 */
public class RainQualityDaoImpl extends BaseDao implements RainQualityDao {
    Rainquality rainquality;
    @Override
    public List<Rainquality> getAll() {
        String sql="select * from rainQuality";
        List<Rainquality> All=new ArrayList<>();
        ResultSet rs=executeQuery(sql);
        try{
            while (rs.next()){
                rainquality=new Rainquality();
                rainquality.setId(rs.getInt("id"));
                rainquality.setDistrictName(rs.getString("districtName"));
                rainquality.setMonitorTime(rs.getString("monitorTime"));
                rainquality.setRain(rs.getInt("rain"));
                rainquality.setMonitoringStation(rs.getString("monitoringStation"));
                rainquality.setMonitoringAddress(rs.getString("monitoringAddress"));
                All.add(rainquality);
            }
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return All;
    }


    @Override
    public int add(String districtName, String monitorTime, int rain, String monitoringStation, String monitoringAddress) {
        String sql="INSERT into rainquality(districtName,monitorTime,rain,monitoringStation,monitoringAddress) VALUES (?,?,?,?,?)";
        //参数数组
        Object[] params={districtName,monitorTime,rain,monitoringStation,monitoringAddress};
        int hangshu=executeUpdate(sql,params);
        return hangshu;
    }


}
